package no.eirikb.bomberman.server;

import java.rmi.Remote;
import java.rmi.RemoteException;
import no.eirikb.bomberman.applet.game.Bomb;
import no.eirikb.bomberman.client.Client;
import no.eirikb.bomberman.shared.Game;
import no.eirikb.bomberman.applet.game.Pos;
import no.eirikb.bomberman.applet.game.PowerUp;
import no.eirikb.bomberman.shared.message.Message;
import no.eirikb.bomberman.shared.User;
import no.eirikb.bomberman.applet.game.Way;
import no.eirikb.bomberman.shared.img.ImageDB;

/**
 *
 * @author eirikb
 */
public interface Server extends Remote {

    /**
     * Registrer a client with user
     * @param client The client the server should reply to
     * @param user The user (Nick,char etc)
     * @return A hash used to increase security. Null if nick is in use
     * @throws java.rmi.RemoteException
     */
    Double registerUser(Client client, User user) throws RemoteException;

    /**
     * Request the image database
     * TODO: Create hash or mage it updatable by event commands
     * @return Image database
     * @throws java.rmi.RemoteException
     */
    ImageDB getImageDB() throws RemoteException;

    /**
     * Disconnect client at leave
     * @param nick Nick of user that should leave
     * @throws java.rmi.RemoteException
     */
    void disconnect(Double hash, String nick) throws RemoteException;

    /**
     * Send chat message
     * @param hash To increase security
     * @param message message to send to user, game of public
     * @return true if user exists, or in game etc...
     * @throws java.rmi.RemoteException
     */
    boolean chat(Double hash, Message message) throws RemoteException;

    /**
     * Create a game
     * @param hash The hash to increase security
     * @param nick Nick of the user that want to create a game
     * @param game The game to create
     * @return True if game was created, fale if not
     * @throws java.rmi.RemoteException
     */
    boolean createGame(Double hash, String nick, Game game) throws RemoteException;

    /**
     * Join a already craeted game
     * @param hash The hash to increase security
     * @param nick Nick of the user that want to join
     * @param gameName Name of the game the user want to join
     * @return True if a spot is available, if not returns false
     * @throws java.rmi.RemoteException
     */
    boolean joinGame(Double hash, String nick, String gameName) throws RemoteException;

    /**
     * Leave a game
     * @param hash The hash to increate security
     * @param nick Nick of the user that wants to leave the game
     * @throws java.rmi.RemoteException
     */
    void leaveGame(Double hash, String nick) throws RemoteException;

    /**
     * Set user as ready to play game, or unready, alternating
     * @param hash The hash to increase security
     * @param nick Nick of the user that is ready
     * @param ready True if ready, false if not ready
     * @throws java.rmi.RemoteException
     */
    void setReady(Double hash, String nick, boolean ready) throws RemoteException;

    /**
     * Recieve the game-list.
     * Used for updating the list from the client
     * @return All the games
     * @throws java.rmi.RemoteException
     */
    Game[] getGameList() throws RemoteException;

    /**
     * User starts walking
     * @param hash The hash to increase security
     * @param nick Nick of the user
     * @param way The way the user wants to walk
     * @param pos Position set IF no button is released
     * @throws java.rmi.RemoteException
     */
    void startWalk(Double hash, String nick, Way way, Pos pos) throws RemoteException;

    /**
     * User stops walking
     * @param hash The hash to increase security
     * @param nick Nick of the user that is ready
     * @param pos Position user stops to walk (used for synchronizing)
     * @throws java.rmi.RemoteException
     */
    void stopWalk(Double hash, String nick, Pos pos) throws RemoteException;

    /**
     * User places a bomb on the map
     * @param hash The hash to increase security
     * @param nick Nick of the user
     * @param bomb The bomb to place out
     * @throws java.rmi.RemoteException
     */
    void setBomb(Double hash, String nick, Bomb bomb) throws RemoteException;

    /**
     * user picks up a powerup
     * @param hash The hash to increase security
     * @param nick Nick of the user
     * @param powerUp PowerUp
     * @throws java.rmi.RemoteException
     */
    void powerUp(Double hash, String nick, PowerUp powerUp) throws RemoteException;
}
